class MyPlugin {
  constructor(options) {
    console.log(options)
  }
  apply(compiler) {
    // webpack的插件的原型必须有这个函数
    // compiler wepack传递进来的内置对象
    let hooks = compiler.hooks;
    hooks.emit.tap('myplugin', function (compilation) {
      let assets = compilation.assets;
      // assets 对应的就是所有打包出来的文件信息
      let str = ``;
      for (let k in assets) {
        str += `#### 文件名是: ${k};大小是${assets[k].size()}\n`
      }
      assets['filesInfo.md'] = {
        source() {
          return str
        },
        size() {
          return str.length
        }
      }
    })
  }
}

module.exports = MyPlugin